//{# ------------------------------------------------------- echarts ---------------------------------------------------- #}
var echartforce = echarts.init(document.getElementById('echartforce'));
var echartcircle = echarts.init(document.getElementById('echartcircle'));
echartforce.showLoading();
echartcircle.showLoading();
var len, graph, categories, forceSettings, circularSettings;
var colors = ['#c23531', '#DA1B73', '#7109AA', '#1719B9', '#00CC00', '#CD0074', '#33CCCC', '#FF9A00'];
var getttextColor = function (edge, color) {
    var edgeText = edge.edgeText;
    var edgeColor;
    if (edge.colorIndex) {
        edgeColor = colors[edge.colorIndex];
    } else {
        edgeColor = color;
    }
    if (!color) {
        color = colors[edge.colorIndex];
    }
    edge.lineStyle = {
        normal: {
            color: color,
            width: 1
        },
        emphasis: {
            color: edgeColor,
            width: 1,
            formatter: function () {
                return edgeText
            }
        }
    };
    edge.label = {
        normal: {
            show: true,
            position: 'middle',
            formatter: function () {
                return edgeText
            },
            textStyle: {
                color: color,
                fontSize: 5
            }
        },
        emphasis: {
            show: true,
            position: 'middle',
            formatter: function () {
                return edgeText
            },
            textStyle: {
                color: "#222222",
                fontSize: 14
            }
        }
    };
};
var echartdata = function (xml, id) {
    echartforce.hideLoading();
    echartcircle.hideLoading();
    graph = echarts.dataTool.gexf.parse(xml);
    categories = [
        {
            "name": "当前企业",
            itemStyle: {
                normal: {color: colors[0], borderWidth: 1, borderColor: "#000000"}
            }
        },
        {
            "name": "企业股东",
            itemStyle: {
                normal: {color: colors[1], borderWidth: 1, borderColor: "#000000"}
            }
        },
        {
            "name": "法人代表",
            itemStyle: {
                normal: {color: colors[2], borderWidth: 1, borderColor: "#000000"}
            }
        },
        {
            "name": "个人股东或高管",
            itemStyle: {
                normal: {color: colors[3], borderWidth: 1, borderColor: "#000000"}
            }
        },
        {
            "name": "企业对外投资",
            itemStyle: {
                normal: {color: colors[4], borderWidth: 1, borderColor: "#000000"}
            }
        },
        {
            "name": "法人对外投资或任职",
            itemStyle: {
                normal: {color: colors[5], borderWidth: 1, borderColor: "#000000"}
            }
        },
        {
            "name": "股东高管对外投资或任职",
            itemStyle: {
                normal: {color: colors[6], borderWidth: 1, borderColor: "#000000"}
            }
        },
        {
            "name": "对外负责个体户",
            itemStyle: {
                normal: {color: colors[7], borderWidth: 1, borderColor: "#000000"}
            }
        }
    ];
    graph.nodes.forEach(function (node) {
        node.itemStyle = null;
        node.value = node.symbolSize;
        if (id == "echartforce") {
            node.symbolSize *= 1;
        } else {
            node.symbolSize /= 2;
        }
        node.category = node.attributes.modularity_class;
        node.x = node.y = null;
        node.draggable = true;
        node.label = {
            normal: {
                show: node.symbolSize > 0  //显示文本
            }
        };
    });
    graph.links.forEach(function (edge) {
        getttextColor(edge, "#999");
    });
    forceSettings = {
        tooltip: {},
        legend: [{
            orient: 'vertical',
            x: 'left',
            data: categories.map(function (a) {
                return a.name;
            })
        }],
        animation: false,
        series: [
            {
                //{#                    color: colors,#}
                name: '企业关联图',
                type: 'graph',
                layout: 'force',
                roam: true,
                label: {
                    normal: {
                        position: "right",
                        textStyle: {
                            color: "#000",
                            fontSize: 12
                        }
                    },
                    emphasis: {
                        show: true
                    }
                },
                tooltip: {
                    padding: 10,
                    borderColor: '#777',
                    borderWidth: 1,
                    formatter: function (obj) {
                        return obj.data.nodeText;
                    }
                },
                edgeSymbol: ['arrow', 'none'],
                data: graph.nodes,
                links: graph.links,
                focusNodeAdjacency: true,
                categories: categories,
                force: {
                    repulsion: 500,
                    edgeLength: 200,
                    layoutAnimation: false
                }
            }
        ]
    };
    circularSettings = {
        tooltip: {},
        legend: [{
            orient: 'vertical',
            x: 'left',
            data: categories.map(function (a) {
                return a.name;
            })
        }],
        animationDurationUpdate: 1500,
        animationEasingUpdate: 'quinticInOut',
        series: [
            {
                //{#                    color: colors,#}
                name: '企业关联图',
                type: 'graph',
                layout: "circular",
                circular: {
                    rotateLabel: true
                },
                center: null,
                label: {
                    normal: {
                        position: "left"
                    }
                },
                tooltip: {
                    padding: 10,
                    borderColor: '#777',
                    borderWidth: 1,
                    formatter: function (obj) {
                        return obj.data.nodeText;
                    }
                },
                edgeSymbol: ['arrow', 'none'],
                data: graph.nodes,
                links: graph.links,
                focusNodeAdjacency: true,
                categories: categories,
                roam: true,
                lineStyle: {
                    normal: {
                        width: 0.5,
                        curveness: 0.3
                    }
                }
            }
        ]
    };
    if (id == "echartforce") {
        echartforce.setOption(forceSettings);
        len = graph.nodes.length;
    }
    if (id == "echartcircle") {
        echartcircle.setOption(circularSettings);
    }
};